//实时数据
function dao(path,method="get",pars={}){
	let promise = new Promise((resolve,reject)=>{
			 var xhr = new XMLHttpRequest();
		
				xhr.open(method,path,true);
			 	xhr.send(JSON.stringify(pars));
			 	xhr.onreadystatechange = function() {
			 	
			 		if (xhr.readyState === 4 && xhr.status === 200) {
			 			var data = JSON.parse(xhr.responseText);
			 	     resolve(data);
			 		} else {
			 			// reject(new Error(xhr.statusText));
			 		}
			 }
	})
	return promise;
}


function dao2(path,callBack,name){
	let  el = document.createElement('script');
	el.type = 'text/javascript';
    el.src=path
	 el.onload=function(e){
		 callBack(window[name]);
		  document.getElementsByTagName('head')[0].removeChild(el);
		  
	 }
	var head = document.getElementsByTagName('head')[0];
	head.appendChild(el);
}
function getNowVal(key){

	 	var path = " https://web.ifzq.gtimg.cn/appstock/app/minute/query?code=" + key;
		return dao(path)
}
function getDately(key,callBack){
	var  path = "https://data.gtimg.cn/flashdata/hushen/latest/daily/"+key+".js?maxage=63201&visitDstTime=2";
   dao2(path,callBack,"latest_daily_data");
	
}

function getYearDately(key,year,callBack){
	//每年日K
	let path = "http://data.gtimg.cn/flashdata/hushen/daily/" + year + "/" +
		key + ".js?visitDstTime=1";
		dao2(path,callBack,"daily_data_"+year);
}

function getLastMonth(key,callBack){
	
	let path = "http://data.gtimg.cn/flashdata/hushen/monthly/" + key + ".js?maxage=43201";
		dao2(path,callBack,"monthly_data");
}